#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <ctype.h>

int main()
{
    int base1, base2;
    char num[1000];
    scanf("%d%d%s", &base1, &base2, num);

    long long ten = 0;
    for (int i = 0; num[i] != '\0'; i++)
    {
        int n = isdigit(num[i]) ? num[i] - '0' : num[i] - 'A' + 10;
        ten = ten * base1 + n;
    }

    int j = 0;
    while (ten)
    {
        int temp = ten % base2;
        if (temp == 0)
            num[j] = '0';
        else
            num[j] = (temp > 9) ? temp - 10 + 'A' : temp + '0';
        j++;
        ten /= base2;
    }
    if (j == 0)
        printf("0");
    else
    {
        for (int i = j - 1; i >= 0; i--)
            printf("%c", num[i]);
    }
    return 0;
}